package repository

import (
	"away.wei/minidevpos/db"
	"away.wei/minidevpos/global"
)

type ProjectDeployRep struct{}

func (s *ProjectDeployRep) Create(dtos []db.ProjectDeploy) error {
	return global.DB.Create(&dtos).Error
}

func (s *ProjectDeployRep) Delete(ids []int) error {
	return global.DB.Delete(&db.ProjectDeploy{}, "id in ?", ids).Error
}

func (s *ProjectDeployRep) Update(dtos []db.ProjectDeploy) []error {
	errs := make([]error, 0)
	for _, v := range dtos {
		err := global.DB.Updates(&v).Error
		if err != nil {
			errs = append(errs, err)
		}
	}
	return errs
}

func (s *ProjectDeployRep) GetProjectId(projectId int) (list []db.ProjectDeploy, err error) {
	dbquery := global.DB.Model(&db.ProjectDeploy{})
	err = dbquery.Where("project_id=?", projectId).Find(&list).Error
	return list, err
}
